home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / xprolog.arc / xprolog.doc < prev   
Encoding:
Text File  |  1987-10-12  |  24.9 KB  |  806 lines

  1.  
  2.  
  3.  
  4.  
  5.             X Prolog Vers. 2.0
  6.  
  7.  
  8.  
  9.     This software is copyrighted by Andreas Toenne.
  10.  
  11.     It may be copied free of charge iff this copyright notice
  12.  
  13.     is left at it's place.
  14.  
  15.  
  16.  
  17.     Andreas Toenne
  18.  
  19.     Computer Science Department
  20.  
  21.     University of Dortmund, W-Germany
  22.  
  23.     
  24.  
  25.     E-mail : 
  26.  
  27.         atoenne@unido.uucp
  28.  
  29.         atoenne@unido.bitnet
  30.  
  31.         ...!seismo!unido!atoenne
  32.  
  33.         
  34.  
  35.  
  36.  
  37.     ***********************************************************
  38.  
  39.     
  40.  
  41.     Note ! This manual is just a quick hack to make Xprolog
  42.  
  43.     available as fast as possible.
  44.  
  45.     Sections that are missing are stated in '<' and '>'
  46.  
  47.     Xprolog follows mostly the Cprolog standard, thus the
  48.  
  49.     Cprolog manual could be of some help to the novice user
  50.  
  51.  
  52.  
  53.     ***********************************************************
  54.  
  55.     
  56.  
  57.  
  58.  
  59.     1. Getting started.
  60.  
  61.     
  62.  
  63.     This program was developed with the Mark Williams C-Compiler Vers. 2.0
  64.  
  65.     It was designed to live on a hard disk!
  66.  
  67.     To start Xprolog simply double click xprolog.ttp without arguments.
  68.  
  69.     Xprolog will try to read it's default image as : C:\BIN\PBOOT
  70.  
  71.     If you don't have this directory or wish to start with another
  72.  
  73.     image, enter the name as an argument for Xprolog.
  74.  
  75.     You may set the enviroment variable BOOTFILE as well.
  76.  
  77.     
  78.  
  79.     1.1 Booting XProlog
  80.  
  81.     
  82.  
  83.     If you start Xprolog for the very first time, you must create
  84.  
  85.     your own image.
  86.  
  87.     This is done by calling Xprolog with the option -b.
  88.  
  89.     Make sure that the bootfile _boot is present in the current directory.
  90.  
  91.     You may save the image with 'save(Imagename).' then.
  92.  
  93.     
  94.  
  95.     1.2 Options
  96.  
  97.     
  98.  
  99.     You can specify the sizes of the various data areas with the
  100.  
  101.     following options. The new size must be given in bytes.
  102.  
  103.     
  104.  
  105.     -p<size>     prototype space
  106.  
  107.     -f<size>    functor space
  108.  
  109.     -r<size>    number of rules (not bytes!)
  110.  
  111.     -c<size>    copystack
  112.  
  113.     -s<size>    THE STACK
  114.  
  115.     -t<size>    trailstack
  116.  
  117.     
  118.  
  119.     The builtin predicate 'statistics' shows the current sizes of
  120.  
  121.     all data areas.
  122.  
  123.  
  124.  
  125.     1.3 General
  126.  
  127.     
  128.  
  129.     The enviroment variable SHELL may be set if you don't have
  130.  
  131.     msh.prg    or want to specify another shell.  (cf.  'system', 'sh')
  132.  
  133.     <Control>C may be pressed anytime during computation.
  134.  
  135.     Xprolog performs an abort then. (cf. 'abort')
  136.  
  137.     
  138.  
  139.     1.4 Explanation of Data Areas
  140.  
  141.     
  142.  
  143.     Prototype: a term in a prolog program
  144.  
  145.     Prototype space: contains all prototypes. Forms a heap.
  146.  
  147.     Rule space: contains descriptors for prolog rules. (clause space)
  148.  
  149.         The rule's terms are kept in the prototype space.
  150.  
  151.     Functor: general descriptor for prolog terms. Contains the name, arity
  152.  
  153.         optional operator definitions and a link to it's rules.
  154.  
  155.         Functors are kept in an avl-tree.
  156.  
  157.     Copystack: keeps copies of prototypes. Grows during unification and
  158.  
  159.         shrinks only upon backtracking.
  160.  
  161.     THE STACK: keeps the computation data that makes up the resolution
  162.  
  163.         tree. Highly dynamic !!
  164.  
  165.     Trailstack: keeps trails (references) for variables that must be
  166.  
  167.         preserved for backtracking. Usually very small.
  168.  
  169.  
  170.  
  171.     1.5 Limitations and Default Values
  172.  
  173.     
  174.  
  175.     - max. 20 arguments in a term
  176.  
  177.     - max. 50 variables (without anonymous) in a prototype term
  178.  
  179.     - max. 15 open streams
  180.  
  181.     - the reader can read terms upto 8000 bytes
  182.  
  183.     - max. 256 characters in a name
  184.  
  185.     - the cpu stack is 32000 bytes wide
  186.  
  187.     
  188.  
  189.     - default shell is 'c:\bin\msh.prg'
  190.  
  191.     - default bootimage is 'c:\bin\pboot'
  192.  
  193.     - default prototype space size is 30000 bytes
  194.  
  195.     - default copystack size if 50000 bytes
  196.  
  197.     - default STACK size is 50000 bytes
  198.  
  199.     - default trailstack size is 800 trail entries
  200.  
  201.     - default number of clauses is 1000
  202.  
  203.     - default functor space is 30000 bytes
  204.  
  205.  
  206.  
  207.     2.0 Error Handling and Debugging
  208.  
  209.     
  210.  
  211.     2.0.1 Fatal Errors
  212.  
  213.     
  214.  
  215.     Fatal errors are :
  216.  
  217.     - not enough memory
  218.  
  219.     - prototype space overflow
  220.  
  221.     - missing main goal to start the machine
  222.  
  223.     - main goal has stopped
  224.  
  225.     - clause space overflow
  226.  
  227.     - missing error goal, iff an recoverable error happens
  228.  
  229.     - functor space overflow
  230.  
  231.     - bad data during boot phase
  232.  
  233.     - invalid prolog image
  234.  
  235.     
  236.  
  237.     Fatal errors print an message and terminate Xprolog.
  238.  
  239.     
  240.  
  241.     2.0.2 Lesser Errors
  242.  
  243.     
  244.  
  245.     These are :
  246.  
  247.     - STACK overflow
  248.  
  249.     - Trailstack overflow
  250.  
  251.     - Copystack overflow
  252.  
  253.     
  254.  
  255.     These errors cause an abort of the current goal. (cf. 'abort')
  256.  
  257.     They are usually caused by an loop or by generally insuffient memory.
  258.  
  259.     
  260.  
  261.     2.0.3 Recoverable Errors
  262.  
  263.     
  264.  
  265.     Recoverable Errors are counted as :
  266.  
  267.     1. Unknown clause.
  268.  
  269.     2. IO failure.
  270.  
  271.     3. Read past EOF.
  272.  
  273.     4. Bad syntax.
  274.  
  275.     5. Too many args/vars.
  276.  
  277.     6. Bad arguments.
  278.  
  279.     7. No valid expression. 
  280.  
  281.     8. User break. (control)C
  282.  
  283.     
  284.  
  285.     Except error 1 these error are caused by builtin predicates.
  286.  
  287.     They have the following meanings :
  288.  
  289.     
  290.  
  291.     1. The current goal refers to an unknown clause. This is normaly due
  292.  
  293.        to a typo or an incomplete program.
  294.  
  295.     2. Some sort of general nastiness. Watch out !!
  296.  
  297.     3. If a read, get, etc. hits the end of the current input stream,
  298.  
  299.        it's argument will be unified with 'end_of_file'.
  300.  
  301.        Note ! This differs from other prolog implementations.
  302.  
  303.        If the programs attemps to read from this stream again, error 3
  304.  
  305.        is the result.
  306.  
  307.     4. This error is due to bad syntax in an prolog term.
  308.  
  309.        Look at the detailed error description of the reader.
  310.  
  311.     5. Xprolog has hard coded limitations for the number of arguments
  312.  
  313.        of a term and the number of variables in a prototype term.
  314.  
  315.        See section 1.5 'Limitations and Default Values'
  316.  
  317.     6. The arguments failed the parameter check for builtins.
  318.  
  319.     7. The user typed <control>C
  320.  
  321.  
  322.  
  323.     When an recoverable error occurs, a new goal is set up.
  324.  
  325.     This is 'error(NumberOfTheError, GoalThatCausedTheError)'.
  326.  
  327.     The clause error should normally print a message on the screen and
  328.  
  329.     fail. However it is possible to correct the error and succeed then.
  330.  
  331.     (Note that error 1 should always lead to a failure)
  332.  
  333.  
  334.  
  335.     2.1 Debugging Predicates
  336.  
  337.     
  338.  
  339.     There are few of them right now.
  340.  
  341.     'debug' switches tracing on.
  342.  
  343.     'nodebug' switches tracing off.
  344.  
  345.     'leash(Value)' sets the amount of tracing data.
  346.  
  347.     The initial value after debug is switched on is 'half'.
  348.  
  349.     The following leash modes exists :
  350.  
  351.     - full    trace on call, retry, exit and fail
  352.  
  353.     - tight    trace on call, retry and fail
  354.  
  355.     - half    trace on call and retry
  356.  
  357.     - loose    trace on call
  358.  
  359.     - off    no trace
  360.  
  361.     
  362.  
  363.     < it is assumed that the reader is familiar with the procedure >
  364.  
  365.     < box control flow model. cf. the prolog primer by Clocksin and >
  366.  
  367.     < Mellish >
  368.  
  369.  
  370.  
  371.     3. Reader and Syntax
  372.  
  373.     
  374.  
  375.     <far too short>
  376.  
  377.  
  378.  
  379.     Generally the reader expects every goal and every program term
  380.  
  381.     to be finished by a dot and a new line!
  382.  
  383.         
  384.  
  385.     To read a prolog program (not an image), you should type
  386.  
  387.     'consult(filenameinsinglequotes).'
  388.  
  389.     If you want to read several files you can shorten the command to
  390.  
  391.     '[filename, filename, ...].'. (cf. list syntax)
  392.  
  393.     The goal 'reconsult(filenameinsinglequotes)' rereads clauses.
  394.  
  395.     That means it abolishes the old clauses before asserting them
  396.  
  397.     from the file. (cf. 'abolish' and 'assert')
  398.  
  399.     The same effect is achieved by preceeding the filename in the
  400.  
  401.     short notation by a '-'.
  402.  
  403.     A special file (cf. IO predicates) is 'user'. This stands for
  404.  
  405.     the terminal.
  406.  
  407.     
  408.  
  409.     When Xprolog is in the top level loop, it reads goals from
  410.  
  411.     the terminal and tries to satisfy them.
  412.  
  413.     When Xprolog consultes a file, it reads terms and tries to assert
  414.  
  415.     them. You can execute goals by preceeding them by ?- or :- .
  416.  
  417.     The only difference between ?- and :- is, that :- generates no
  418.  
  419.     answer (ie. 'no' or 'yes') and no alternatives are tried.
  420.  
  421.     
  422.  
  423.     3.1 Prolog Syntax
  424.  
  425.     
  426.  
  427.     3.1.1 Terms
  428.  
  429.     
  430.  
  431.     Terms are
  432.  
  433.     - constants
  434.  
  435.     - variables
  436.  
  437.     - structures (generally known as compound terms)
  438.  
  439.     
  440.  
  441.     Constants are
  442.  
  443.     - integers    (all natural numbers that fit in two machine words)
  444.  
  445.     - atoms        (actual atoms are structures without arguments)
  446.  
  447.     The name for an atom must start with a lowercase letter and may
  448.  
  449.     contain any letter, digit and the '_'.
  450.  
  451.     If you want to use any character, you should enclose the name in
  452.  
  453.     single quotes.
  454.  
  455.     < there are some special 'standalone' character which form a >
  456.  
  457.     < valid name. cf. CM 'Programming in Prolog' >
  458.  
  459.     
  460.  
  461.     Variables must start with an uppercase letter or with an '_'.
  462.  
  463.     If you need a variable only once, you may use the anonymous
  464.  
  465.     variable '_'.
  466.  
  467.     
  468.  
  469.     Structures comprises of a functor and a sequence of terms, it's
  470.  
  471.     arguments.
  472.  
  473.     A functor is characterised by the name and the arity.
  474.  
  475.     (Number of arguments)
  476.  
  477.     The sequence of terms must be written comma seperated in round
  478.  
  479.     brackets. eg. testfunctor(first, second, third).
  480.  
  481.  
  482.  
  483.     3.1.2 Lists
  484.  
  485.     
  486.  
  487.     As lists are the most used data structures in prolog, the reader
  488.  
  489.     offers a simple way of writing them.
  490.  
  491.     Lists are either the empty list [] or a structure with the binary
  492.  
  493.     functor '.' and two arguments, the head and tail of the list.
  494.  
  495.     The standart syntax for a list like
  496.  
  497.     
  498.  
  499.         .
  500.  
  501.            / \
  502.  
  503.         first .
  504.  
  505.              / \
  506.  
  507.          second .
  508.  
  509.                 / \
  510.  
  511.          third    []
  512.  
  513.          
  514.  
  515.     is .(first, .(second, .(third, []))).
  516.  
  517.     The simpler syntax is [first, second, third].
  518.  
  519.     If the tail of the above example is not the empty list, but a
  520.  
  521.     random term one can write
  522.  
  523.     [first, second, third | RandomTermIsTailOfTheList].
  524.  
  525.     Thus the above example could be written
  526.  
  527.     [first, second, third | []] as well.
  528.  
  529.     
  530.  
  531.     Another notation for lists is the string.
  532.  
  533.     Strings are lists of integers which correspond to ASCII characters.
  534.  
  535.     Strings are written in double quotes.
  536.  
  537.     "Prolog" is the same as [80, 114, 111, 108, 111, 103].
  538.  
  539.  
  540.  
  541.     3.2 Operators
  542.  
  543.  
  544.  
  545.     It is possible to declare unary and binary functors as operators.
  546.  
  547.     These operators are only of interest to the reader and do not add
  548.  
  549.     any computational power to Xprolog.
  550.  
  551.     For instance the valid prolog term +(1,2) may as well be written
  552.  
  553.     as 1 + 2.
  554.  
  555.     An operator comprises of the sort of operator, the preccedence
  556.  
  557.     and of the atom that should be an operator.
  558.  
  559.     < For a detailed description of operators see CM >
  560.  
  561.  
  562.  
  563.     The following operators are hard coded in Xprolog :
  564.  
  565.     (List from Xprolog sources, file init.c)
  566.  
  567.     { ":-", &XFXFUNCTOR, 255},
  568.  
  569.     { "?-", &FXFUNCTOR, 255},
  570.  
  571.     { ":-", &FXFUNCTOR, 255},
  572.  
  573.     { ";", &XFYFUNCTOR, 254},
  574.  
  575.     { ",", &XFYFUNCTOR, 253},
  576.  
  577.     { "spy", &FXFUNCTOR, 250},
  578.  
  579.     { "nospy", &FXFUNCTOR, 250},
  580.  
  581.     { "\\", &FXFUNCTOR, 60},        /* a single backslash !!! */
  582.  
  583.     { "not", &FXFUNCTOR, 60},
  584.  
  585.     { ".", &XFYFUNCTOR, 51},
  586.  
  587.     { "is", &XFXFUNCTOR, 40},
  588.  
  589.     { "=..", &XFXFUNCTOR, 40},
  590.  
  591.     { "=", &XFXFUNCTOR, 40},
  592.  
  593.     { "\\=", &XFXFUNCTOR, 40},
  594.  
  595.     { "<", &XFXFUNCTOR, 40},
  596.  
  597.     { "=<", &XFXFUNCTOR, 40},
  598.  
  599.     { ">=", &XFXFUNCTOR, 40},
  600.  
  601.     { ">", &XFXFUNCTOR, 40},
  602.  
  603.     { "==", &XFXFUNCTOR, 40},
  604.  
  605.     { "\\==", &XFXFUNCTOR, 40},
  606.  
  607.     { "=:=", &XFXFUNCTOR, 40},
  608.  
  609.     { "=\\=", &XFXFUNCTOR, 40},
  610.  
  611.     { "@<", &XFXFUNCTOR, 40},
  612.  
  613.     { "@>", &XFXFUNCTOR, 40},
  614.  
  615.     { "@=<", &XFXFUNCTOR, 40},
  616.  
  617.     { "@>=", &XFXFUNCTOR, 40},
  618.  
  619.     { "-", &FXFUNCTOR, 31},
  620.  
  621.     { "-", &YFXFUNCTOR, 31},
  622.  
  623.     { "+", &YFXFUNCTOR, 31},
  624.  
  625.     { "/\\", &YFXFUNCTOR, 31},
  626.  
  627.     { "\\/", &YFXFUNCTOR, 21},
  628.  
  629.     { "*", &YFXFUNCTOR, 21},
  630.  
  631.     { "/", &YFXFUNCTOR, 21},
  632.  
  633.     { "mod", &XFXFUNCTOR, 11},
  634.  
  635.     { "<<", &XFXFUNCTOR, 11},
  636.  
  637.     { ">>", &XFXFUNCTOR, 11},
  638.  
  639.  
  640.  
  641.     An operator declaration may be overridden but cannot be erased.
  642.  
  643.     Operator types are : fx fy xf yf xfx xfy yfx yfy.
  644.  
  645.     Operators are declared by :
  646.  
  647.     'op(precedence, type, atom)'.
  648.  
  649.     The precedence may be in the range 1-255. (cf. above)
  650.  
  651.     
  652.  
  653.     - Brackets must be seperated from an operator by a blank.
  654.  
  655.     - Arguments to a structure may have a maximal precedence of 254.
  656.  
  657.       If it is necessary to have higher precedences, enclose the term
  658.  
  659.       in brackets.
  660.  
  661.     - To use an operator as an ordinary atom, enclose it in brackets too.
  662.  
  663.  
  664.  
  665.     4.0 System Hooks and Hacks
  666.  
  667.     
  668.  
  669.     The following builtin (c defined) predicates are not intended for
  670.  
  671.     use in a 'normal' prolog program but are used for interaction
  672.  
  673.     and manipulation of the underlying system.
  674.  
  675.     
  676.  
  677.     halt.
  678.  
  679.         The proper way to stop Xprolog and return to the desktop.
  680.  
  681.  
  682.  
  683.     abort.
  684.  
  685.         Aborts the current pending goals, cleans the trail, copy
  686.  
  687.         and resolutionstack and restarts the main goal.
  688.  
  689.         
  690.  
  691.     fileerrors.
  692.  
  693.         After fileerrors was called, any error during io leads
  694.  
  695.         to an error message and to an abort.
  696.  
  697.         
  698.  
  699.     nofilerrors.
  700.  
  701.         After nofilerrorsw as called, io error lead to an failure
  702.  
  703.         of the builtin predicate.
  704.  
  705.         
  706.  
  707.     sh.
  708.  
  709.         Invokes a command shell. If the enviroment variable SHELL
  710.  
  711.         is not set, the default shell will be used.
  712.  
  713.         
  714.  
  715.     system(atom).
  716.  
  717.         Invokes the command atom through a command shell.
  718.  
  719.         
  720.  
  721.     statistics.
  722.  
  723.         Returns some usefull statistics.
  724.  
  725.         
  726.  
  727.     prompt(old, new).
  728.  
  729.         Unifies old and new to the old an new prompt. Usefull for
  730.  
  731.         determine the current prompt or changeing the prompt.
  732.  
  733.         (see _boot for an example)
  734.  
  735.         
  736.  
  737.     $clause(head, body, don't_touch_me)
  738.  
  739.         Hook for implementing 'clause(head, body)'.
  740.  
  741.         If invoked from the call port, the third argument must be
  742.  
  743.         an unbound variable.
  744.  
  745.         $clause tries to unify head and body with the head and body
  746.  
  747.         of the first fitting clause descriptor.
  748.  
  749.         The third argument is then CHANGED(literally!) to an
  750.  
  751.         integer with the adress of the current clause descriptor as
  752.  
  753.         it's value.
  754.  
  755.         If $clause is reinvoked from the retry port, the next fitting
  756.  
  757.         clause descriptor is searched and the integer is advanced.
  758.  
  759.         Thus it is possible to find all clauses in the database.
  760.  
  761.         If there is no further clause, the third argument is
  762.  
  763.         recreated as a fresh variable.
  764.  
  765.  
  766.  
  767.     debug.
  768.  
  769.         Switches debug mode on. Leash is set to half.
  770.  
  771.         
  772.  
  773.     nodebug.
  774.  
  775.         Switches debug mode off.
  776.  
  777.         
  778.  
  779.     $functor(name, arity, don't_touch_me)
  780.  
  781.         General hook. (Used in 'listing' for instance)
  782.  
  783.         The third argument is used as in $clause, but holds now
  784.  
  785.         the adress of the last tried functor.
  786.  
  787.         $functor returns all known functors. (through backtracking)
  788.  
  789.         
  790.  
  791.     $goalvars(list)
  792.  
  793.         Hook for the toplevel interpreter loop.
  794.  
  795.         When the reader reads a prolog term, all encountered
  796.  
  797.         variables and their names are stored in an internal
  798.  
  799.         symbol table.
  800.  
  801.         To save these variables for later purposes (prompting
  802.  
  803.         the results) one should call $goalvars.
  804.  
  805.         $goalvars builds a list of ',' terms that hold the variable's
  806.  
  807.         name and the variable itself.
  808.  
  809.         For example the term 'test(FirstVariable, _, _234)'
  810.  
  811.         results in [('FirstVariable', _23), ('_234', _24)].
  812.  
  813.  
  814.  
  815.     $more(variable)
  816.  
  817.         Hook for the toplevel interpreter loop.
  818.  
  819.         $more unifies the argument with 'yes' iff there is
  820.  
  821.         a backtrack log for a goal that was called after the
  822.  
  823.         parents goal was called. (difficult ?)
  824.  
  825.         Example: in the conjunction of goals
  826.  
  827.         a, b, call(C), more(VARIABLE), d.
  828.  
  829.         the VARIABLE is set to yes iff the goals a, b or the
  830.  
  831.         meta goal C offers untried alternatives.
  832.  
  833.         Thus $more is used to determine if the user's goal had
  834.  
  835.         some alternatives.
  836.  
  837.         (see _boot for a working example)
  838.  
  839.  
  840.  
  841.     $prompt(atom)
  842.  
  843.         $prompt is used to write a prompt. It is a hack for
  844.  
  845.         a programming mistake that makes Xprolog sometimes think
  846.  
  847.         it has just read an empty line.
  848.  
  849.         (And then it shows a new prompt which is unwanted)
  850.  
  851.         < this bug will probably be removed in later versions >
  852.  
  853.         
  854.  
  855.     protect(list_of_structures)
  856.  
  857.         All given structures (precisely their functors) are
  858.  
  859.         marked as protected.
  860.  
  861.         Afterwards they cannot be removed by abolish or retract.
  862.  
  863.         Hint : use anonymous variables or integers as arguments.
  864.  
  865.         
  866.  
  867.     unprotect(list_of_structures)
  868.  
  869.         Reverse the effect of protect.
  870.  
  871.         
  872.  
  873.     hide(list_of_structures)
  874.  
  875.         All given structures are marked as hidden.
  876.  
  877.         They won't be returned by $functor.
  878.  
  879.         
  880.  
  881.     reveal(list_of_structures)
  882.  
  883.         Reverse the effects of hide.
  884.  
  885.         
  886.  
  887.     save(atom)
  888.  
  889.         Saves the current data in the prototype space,
  890.  
  891.         clause space and functor space in an image with the given name.
  892.  
  893.         Note that images between different processor types are
  894.  
  895.         incompatible.
  896.  
  897.         The current sizes of all data areas are saved too.
  898.  
  899.         If Xprolog is started with such an image, the options are
  900.  
  901.         overridden by the saved area sizes.
  902.  
  903.         
  904.  
  905.     reboot
  906.  
  907.         Restarts Xprolog without loading it again.
  908.  
  909.         Usefull after the database was screwed up.
  910.  
  911.         
  912.  
  913.     $leash(number)
  914.  
  915.         Sets the port bitmask for the tracer.
  916.  
  917.         (the following lines are from Xprolog sources, prolog.h)
  918.  
  919.         #define CALL_PORT     0x1
  920.  
  921.         #define FAIL_PORT    0x2
  922.  
  923.         #define RETRY_PORT    0x4
  924.  
  925.         #define EXIT_PORT    0x8
  926.  
  927.         With $leash it is possible to trace a selected set of
  928.  
  929.         ports.
  930.  
  931.         
  932.  
  933.     reconsulting(number)
  934.  
  935.         Sets the reconsulting flag to number.
  936.  
  937.         If 1, reconsult mode is active, if 0 it is inactive.
  938.  
  939.  
  940.  
  941.     Xprolog offers a very special feature.
  942.  
  943.     One can write 'special case' predicates in C and the more general
  944.  
  945.     procedure in prolog. This feature is currently implemented in
  946.  
  947.     the append predicate only.
  948.  
  949.     The C predicate for append assumes that the first two arguments are
  950.  
  951.     proper lists and unifies the appended lists with the third argument.
  952.  
  953.     If this fails, the 'standard' prolog procedure is used.
  954.  
  955.     (ie. append consist of three clauses, the first is a builtin
  956.  
  957.     c function and the second and third are written in prolog)
  958.  
  959.     < due to a bug listing can't show those procedures >
  960.  
  961.     
  962.  
  963.     5.0 IO Predicates
  964.  
  965.     
  966.  
  967.     Up to 15 streams may be open at any one time.
  968.  
  969.     Everytime one stream is the current input stream and another
  970.  
  971.     stream the current output stream.
  972.  
  973.     If no stream is opened, the users terminal acts like a file.
  974.  
  975.     This is the default stream 'user'.
  976.  
  977.     Filenames must be specified as in the underlying operating system.
  978.  
  979.     Filenames are simple atoms, and must be quoted if necessary.
  980.  
  981.     Normaly IO error cause an abort, but if 'nofileerrors' was called,
  982.  
  983.     the predicate simply fails.
  984.  
  985.     The end of file of the current input stream is signalled by the
  986.  
  987.     atom 'end_of_file'.
  988.  
  989.     
  990.  
  991.     5.1 Reading Programs
  992.  
  993.     
  994.  
  995.     consult(filename)
  996.  
  997.         Reads the clauses in the file and asserts them. (cf. sect. 3.0)
  998.  
  999.  
  1000.  
  1001.     reconsult(filename)
  1002.  
  1003.         Like consult, except that the procedures that will be
  1004.  
  1005.         redefined are deleted before asserting the new clauses.
  1006.  
  1007.         
  1008.  
  1009.     [filename|filenames]
  1010.  
  1011.         Each specified file in the list is consulted, or reconsulted
  1012.  
  1013.         if the filename is preceeded by a '-'.
  1014.  
  1015.         
  1016.  
  1017.     5.2 File Handling
  1018.  
  1019.     
  1020.  
  1021.     see(filename)
  1022.  
  1023.         The file becomes the new current input stream.
  1024.  
  1025.         If the file was not opened yet, it will be opened.
  1026.  
  1027.         
  1028.  
  1029.     seeing(filename)
  1030.  
  1031.         The filename will be unified with the name of the
  1032.  
  1033.         current input stream.
  1034.  
  1035.         
  1036.  
  1037.     seen
  1038.  
  1039.         The current input stream is closed and user becomes
  1040.  
  1041.         the new current input stream.
  1042.  
  1043.         
  1044.  
  1045.     tell(filename)
  1046.  
  1047.         Opens the file (if not open) and makes it the new
  1048.  
  1049.         current output stream.
  1050.  
  1051.         
  1052.  
  1053.     telling(filename)
  1054.  
  1055.         The filename will be unified with the name of the
  1056.  
  1057.         current output stream.
  1058.  
  1059.         
  1060.  
  1061.     told
  1062.  
  1063.         The current ouput stream is closed and user
  1064.  
  1065.         becomes the new current output stream.
  1066.  
  1067.         
  1068.  
  1069.     close(filename)
  1070.  
  1071.         Closes filename.
  1072.  
  1073.         
  1074.  
  1075.     fileerrors
  1076.  
  1077.         Any IO error will cause an abort.
  1078.  
  1079.         
  1080.  
  1081.     nofileerrors
  1082.  
  1083.         Any IO error will just fail the predicate.
  1084.  
  1085.         
  1086.  
  1087.     exists(filename)
  1088.  
  1089.         Succeeds if the file exists and is writeable.
  1090.  
  1091.         
  1092.  
  1093.     rename(old, new)
  1094.  
  1095.         Renames the file old to new.
  1096.  
  1097.         If new is [], then old is removed.
  1098.  
  1099.         
  1100.  
  1101.     5.3 Input Output
  1102.  
  1103.     
  1104.  
  1105.     read(Term)
  1106.  
  1107.         A term (delimited by '.' and a new line) is read and
  1108.  
  1109.         unified with Term.
  1110.  
  1111.  
  1112.  
  1113.     read_line(List)
  1114.  
  1115.         The next line is read and List is unified with the
  1116.  
  1117.         list of characters in that line. Ie. the line
  1118.  
  1119.         is treated as a string.
  1120.  
  1121.         
  1122.  
  1123.     write(Term)
  1124.  
  1125.         The Term is written to the output stream.
  1126.  
  1127.         
  1128.  
  1129.     writeq(Term)
  1130.  
  1131.         The Term is written with it's names quoted where
  1132.  
  1133.         necessary. The output of writeq can be reread by the
  1134.  
  1135.         reader.
  1136.  
  1137.         
  1138.  
  1139.     display(Term)
  1140.  
  1141.         Same as write, but only the prefix notation of terms
  1142.  
  1143.         is used.
  1144.  
  1145.  
  1146.  
  1147.     write_line(String)
  1148.  
  1149.         The String(list of characters) is written.
  1150.  
  1151.         The line is terminated by a line feed.
  1152.  
  1153.         
  1154.  
  1155.     print(Term)
  1156.  
  1157.         Hook for including a pretty printer.
  1158.  
  1159.         Variables are printed with write, but other terms
  1160.  
  1161.         are written with 'portray(Term)'.
  1162.  
  1163.         
  1164.  
  1165.     nl.
  1166.  
  1167.         A new line is started on the output stream.
  1168.  
  1169.         
  1170.  
  1171.     get0(char)
  1172.  
  1173.         The next character is read and it's ASCII code is unified
  1174.  
  1175.         with char.
  1176.  
  1177.         Note that on a end of file on the current input stream
  1178.  
  1179.         get0 returns not an integer but 'end_of_file'.
  1180.  
  1181.         
  1182.  
  1183.     get(char)
  1184.  
  1185.         Same as get0, but only nonblank printable characters are
  1186.  
  1187.         read. Other character are skipped.
  1188.  
  1189.         
  1190.  
  1191.     skip(char)
  1192.  
  1193.         Skips characters until char is found.
  1194.  
  1195.         
  1196.  
  1197.     put(char)
  1198.  
  1199.         Prints the character with the ASCII code char.
  1200.  
  1201.         
  1202.  
  1203.     tab(N)
  1204.  
  1205.         Prints N spaces on the output stream.
  1206.  
  1207.  
  1208.  
  1209.     flush
  1210.  
  1211.         Flushes the current output stream. Usefull
  1212.  
  1213.         for buffered IO.
  1214.  
  1215.         
  1216.  
  1217.     seek(X)
  1218.  
  1219.         Unifies the current position in the current input
  1220.  
  1221.         stream with X.
  1222.  
  1223.  
  1224.  
  1225.     get_key(char, scancode)
  1226.  
  1227.         Special predicate for Atari ST only.
  1228.  
  1229.         Reads any character from the keyboard without echo!!
  1230.  
  1231.         Returns the ASCII code in char and the scancode.
  1232.  
  1233.         The scancode is the position information from the
  1234.  
  1235.         keyboard. (see your copy of the Atari ST internals)
  1236.  
  1237.  
  1238.  
  1239.     6.0 Arithmetic
  1240.  
  1241.     
  1242.  
  1243.     Note that Xprolog has only integers and no floats as in
  1244.  
  1245.     Cprolog.
  1246.  
  1247.     
  1248.  
  1249.     Arithmetic is performed by builtins which take arithmetic
  1250.  
  1251.     expressions as arguments.
  1252.  
  1253.     Valid arithmetic expresssions are (when x and y are expressions) 
  1254.  
  1255.     
  1256.  
  1257.     x+y        addition
  1258.  
  1259.     x-y        subtraction
  1260.  
  1261.     x*y        multiplication
  1262.  
  1263.     x/y        integer division
  1264.  
  1265.     x mod y     x modulo y
  1266.  
  1267.     - x        minus
  1268.  
  1269.     x /\ y        bitwise conjunction
  1270.  
  1271.     x \/ y        bitwise disjunction
  1272.  
  1273.     x << y        bitwise leftshift of x by y bits
  1274.  
  1275.     x >> y        bitwise rightshift
  1276.  
  1277.     \x        bitwise negation
  1278.  
  1279.     cputime        number of milliseconds since Xprolog started
  1280.  
  1281.     heapused    used space in the prototype space in bytes
  1282.  
  1283.     [character]    the ASCCI code of the character
  1284.  
  1285.     any Number
  1286.  
  1287.     
  1288.  
  1289.     Builtin predicates that evaluate expressions are
  1290.  
  1291.     
  1292.  
  1293.     Z is X
  1294.  
  1295.         X is evaluated and Z is unified with the result.
  1296.  
  1297.         
  1298.  
  1299.     X =:= Y
  1300.  
  1301.         The values of X and Y are equal.
  1302.  
  1303.         
  1304.  
  1305.     X =\= Y
  1306.  
  1307.         The values of X and Y are not equal.
  1308.  
  1309.         
  1310.  
  1311.     X < Y
  1312.  
  1313.         The value of X is less the value of Y.
  1314.  
  1315.         
  1316.  
  1317.     X > Y
  1318.  
  1319.     
  1320.  
  1321.     X =< Y
  1322.  
  1323.     
  1324.  
  1325.     X >= Y
  1326.  
  1327.  
  1328.  
  1329.     7.0 Convenience and Control
  1330.  
  1331.     
  1332.  
  1333.     P , Q
  1334.  
  1335.         P and Q.
  1336.  
  1337.         
  1338.  
  1339.     P ; Q
  1340.  
  1341.         P or Q.
  1342.  
  1343.         
  1344.  
  1345.     true.
  1346.  
  1347.         Always succeeds.
  1348.  
  1349.         
  1350.  
  1351.     fail.
  1352.  
  1353.         Never succeeds.
  1354.  
  1355.         
  1356.  
  1357.     X = Y
  1358.  
  1359.         X is unified with Y. Defined as 'X=Y.'
  1360.  
  1361.         
  1362.  
  1363.     !
  1364.  
  1365.         The cut. Discard all pending choices since the parent
  1366.  
  1367.         goal was started.
  1368.  
  1369.         
  1370.  
  1371.     repeat
  1372.  
  1373.         Has infinite choices.
  1374.  
  1375.         Defined as if by :
  1376.  
  1377.         repeat.
  1378.  
  1379.         repeat :- repeat.
  1380.  
  1381.  
  1382.  
  1383.     { clause }
  1384.  
  1385.         Same as assert((clause)).
  1386.  
  1387.  
  1388.  
  1389.     8.0 Meta Logic
  1390.  
  1391.     
  1392.  
  1393.     var(X)
  1394.  
  1395.         X is a variable.
  1396.  
  1397.         
  1398.  
  1399.     nonvar(X)
  1400.  
  1401.         X is not a variable.
  1402.  
  1403.     
  1404.  
  1405.     atom(X)
  1406.  
  1407.         X is an atom.
  1408.  
  1409.         
  1410.  
  1411.     integer(X)
  1412.  
  1413.         X is an integer.
  1414.  
  1415.         
  1416.  
  1417.     atomic(X)
  1418.  
  1419.         X is an atom or an integer.
  1420.  
  1421.  
  1422.  
  1423.     structure(X)
  1424.  
  1425.         X is a structured term. (known as compound term)
  1426.  
  1427.         Note that atom(X) implies structure(X).
  1428.  
  1429.  
  1430.  
  1431.     builtin(X)
  1432.  
  1433.         X is a built in predicate
  1434.  
  1435.         
  1436.  
  1437.     functor(Term, Name, Arity)
  1438.  
  1439.         If Term is given, Name and Arity are set to the name and
  1440.  
  1441.         arity of the Term's functor.
  1442.  
  1443.         If Term is not given (ie. a unbound variable) a structure
  1444.  
  1445.         is generated (with anonymous variables as arguments)
  1446.  
  1447.         with the given name and arity.
  1448.  
  1449.         
  1450.  
  1451.     arg(N, Term, X)
  1452.  
  1453.         Unifies X with the N's argument of Term.
  1454.  
  1455.         
  1456.  
  1457.     Term =.. List
  1458.  
  1459.         List is a List whose head is an atom corresponding to
  1460.  
  1461.         the functor of Term and its tail is the argument list of Term.
  1462.  
  1463.         If Term is not given, List must be instantiated.
  1464.  
  1465.         Examples:
  1466.  
  1467.         product(0,N,N-1) =.. [product,0,N,N-1].
  1468.  
  1469.         X =.. [1,a,b] will fail as 1 is no valid name.
  1470.  
  1471.         
  1472.  
  1473.     name(Atom, List)
  1474.  
  1475.         If Atom is given, List will be unified with the list
  1476.  
  1477.         of the ASCII codes of Atom's name.
  1478.  
  1479.         If Atom is not given, it is unified with an atom whose
  1480.  
  1481.         name is build by the list of ASCII codes.
  1482.  
  1483.         i.e. name(prolog, "prolog").
  1484.  
  1485.         
  1486.  
  1487.     call(Goal)
  1488.  
  1489.         The Goal is executed as if the Goal appeared in the
  1490.  
  1491.         place of call(Goal). Note that the Cut ('!') is local
  1492.  
  1493.         to the Goal.
  1494.  
  1495.         
  1496.  
  1497.     
  1498.  
  1499.     9.0 Term Comparison
  1500.  
  1501.     
  1502.  
  1503.     X == Y
  1504.  
  1505.         Test if X and Y are strictly equal.
  1506.  
  1507.         
  1508.  
  1509.     X \== Y
  1510.  
  1511.         Test if X and Y are not strictly equal.
  1512.  
  1513.         
  1514.  
  1515.     X @< Y
  1516.  
  1517.         Test if X is less than Y in the standard order.
  1518.  
  1519.         < standard order as in Cprolog >
  1520.  
  1521.         
  1522.  
  1523.     X @> Y
  1524.  
  1525.     
  1526.  
  1527.     X @=< Y
  1528.  
  1529.     
  1530.  
  1531.     X @>= Y
  1532.  
  1533.     
  1534.  
  1535.     compare(Op, X, Y)
  1536.  
  1537.         Aplies Op to X and Y.
  1538.  
  1539.         Op may be '<', '>', '='.
  1540.  
  1541.  
  1542.  
  1543.     subatom(first, second)
  1544.  
  1545.         Checks if the name of the first atom lies in the name
  1546.  
  1547.         of the second atom.
  1548.  
  1549.         
  1550.  
  1551.     subATOM(first, second)
  1552.  
  1553.         Like subatom but case independent.
  1554.  
  1555.  
  1556.  
  1557.     10.0 Database
  1558.  
  1559.     
  1560.  
  1561.     assert(Clause)
  1562.  
  1563.         Same as assertz.
  1564.  
  1565.         
  1566.  
  1567.     asserta(Clause)
  1568.  
  1569.         Adds the clause as the first clause of the procedure.
  1570.  
  1571.         
  1572.  
  1573.     assertz(Clause)
  1574.  
  1575.         Adds the clause as the last clause of the procedure.
  1576.  
  1577.         
  1578.  
  1579.     clause(Head, Body)
  1580.  
  1581.         Head must be bound to a structure.
  1582.  
  1583.         The Database is searched for a matching clause.
  1584.  
  1585.         Body is the unified with the body of the found clause.
  1586.  
  1587.         If we found a fact, Body will be unified with 'true'.
  1588.  
  1589.         Clause may be retried to get all matching clauses.
  1590.  
  1591.         
  1592.  
  1593.     retract(Head)
  1594.  
  1595.         The first matching clause is remove from the database.
  1596.  
  1597.         
  1598.  
  1599.     abolish(Name, Arity)
  1600.  
  1601.         Removes all clauses whose name is Name and arity is Arity.
  1602.  
  1603.         
  1604.  
  1605.     !! Note !! Currently no check is made to prevent a program
  1606.  
  1607.     from retracting itself. Clauses are removed immediately.
  1608.  
  1609.     This may result even in a crash of Xprolog !!!!
  1610.  
  1611.